var editor; // use a global for the submit and return data rendering
var table;
var userTypeId=0;
var user;
var communityId="";

function getUrl(url,params) {
    for (var i=0;i<params.length;i++){
        if ($("#"+params[i]).val()!= "") {
            url = url + "&"+params[i]+"=" + $("#"+params[i]).val();
        }
    }
    return url;

}
$(document).ready(function () {
    $.ajax({
        url: '/commis/api/user/currentUser',
        type: "GET",
        async: false,
        dataType: 'json',
        data: {

        },
        success: function (response) {
            if (response.status==0) {
                console.log("用户存在");
                user =response.data;
                userTypeId=user.userTypeId;
                if(userTypeId==4){
                    communityId=user.communityId;
                    areaUrl=areaUrl+"&communityId="+communityId;
                }
                console.log(userTypeId);
            } else if (response.status==1) {
                alert("登录用户已经过期，请重新登录");
                window.parent.location.href = "../../login.html";
            }
        },error: function (msg) {
            alert("登录用户已经过期，请重新登录");
            window.parent.location.href = "../../login.html";
        }
    })

   
   



    var fields=[
        /*{
            label: "填报时间:",
            name: "registerTime"
        },*/ {
            label: "独生子女补贴费:",
            name: "dsznSub"
        }, {
            label: "工作津贴:",
            name: "workSub"
        }, {
            label: "生活补贴:",
            name: "existSub"
        }, {
            label: "月奖金:",
            name: "monthBonus"
        } ,{
            label: "绩效奖金:",
            name: "perBonus"
        }/*, {
            label: "养老系数:",
            name: "pensionRatio"
        }, {
            label: "医疗系数:",
            name: "medicareRatio"
        }, {
            label: "失业系数:",
            name: "unemploymentRatio"
        }, {
            label: "公积金系数:",
            name: "providentFund"
        }, {
            label: "个人所得税系数:",
            name: "incomeTaxRatio"
        }, {
            label: "补扣公积金:",
            name: "bkgjj"
        }, {
            label: "补扣三险:",
            name: "bksx"
        }, {
            label: "事假系数:",
            name: "sjRatio"
        }*/
    ];
    editor = new $.fn.dataTable.Editor({
        ajax: {
            create: {
                type: 'POST',
                url: '/commis/api/fixedItem/create'
            },
            edit: {
                type: 'PUT',
                url: '/commis/api/fixedItem/edit?id=_id_'
            },
            remove: {
                type: 'DELETE',
                url: '/commis/api/fixedItem/remove?id=_id_'
            }
        },
        i18n: {
            create: {
                title: "新增记录",
                submit: "添加"
            },
            edit: {
                title: "修改记录",
                submit: "修改",
                confirm: "您确定要修改这 %d 条记录吗?"
            },
            remove: {
                title: "删除记录",
                submit: "删除",
                confirm: "您确定要删除这 %d 条记录吗?"
            }
        },
        idSrc: 'fixedItemId',
        table: "#fixedItemTable",
        fields: fields
    });


    var buttons = [];
    var select = true;
    if (userTypeId == 1) {
        select = true;
        buttons = [
            {extend: "create", editor: editor, text: "添加", className: 'btn btn-primary'}
        ];
        console.log(buttons);


    } else if (userTypeId == 2) {
        select = false;
        buttons = [
        ];

    } else if (userTypeId == 3||userTypeId == 6||userTypeId == 7||userTypeId == 8||userTypeId == 9) {
        select = false;
        buttons = [];

    } else if (userTypeId == 4) {
        select = false;
        buttons = [];

    }

    table = $('#fixedItemTable').DataTable({

        dom: "Bfrtip",
        ajax: "/commis/api/fixedItem/pageDatatables?communityId="+communityId,
        autoWidth:true,
        responsive: true,
        pageLength: 10,


        serverSide: true,
        processing: true,
        lengthChange: false,//是否允许用户改变表格每页显示的记录数
        ordering: false,//是否允许用户排序
        paging: true,//是否分页
        pagingType: "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
        searching: false,//是否开始本地搜索
        stateSave: false,//刷新时是否保存状态
        autoWidth: true,//自动计算宽度
        language: {
            emptyTable: "没有数据",
            search: "搜索:",
            paginate: {
                first: "首页",
                previous: "上一页",
                next: "下一页",
                last: "尾页"

            },
            select: {
                rows: {
                    _: "选中 %d 行",
                    1: "选中 1 行"
                },
                columns: "选中 %d 列"
            },
            lengthMenu: "每页 _MENU_ 条记录",
            zeroRecords: "没有找到记录",
            info: "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )，共 _TOTAL_ 项",
            infoEmpty: "无记录",
            infoFiltered: "(从 _MAX_ 条记录过滤)"
        },
        columns: [
            {
                data: 'registerTime', defaultContent: ""
            },
            {
                data: 'dsznSub', defaultContent: ""
            },{
                data: 'workSub', defaultContent: ""
            }, {
                data: 'existSub', defaultContent: ""
            }, {
                data: 'monthBonus', defaultContent: ""
            }, {
                data: 'perBonus', defaultContent: ""
            }/*, {
                data: 'pensionRatio', defaultContent: ""
            }, {
                data: 'medicareRatio', defaultContent: ""
            }, {
                data: 'unemploymentRatio', defaultContent: ""
            }, {
                data: 'providentFund', defaultContent: ""
            }, {
                data: 'incomeTaxRatio', defaultContent: ""
            }, {
                data: 'bkgjj', defaultContent: ""
            }, {
                data: 'bksx', defaultContent: ""
            }, {
                data: 'sjRatio', defaultContent: ""
            }*/],
        select: select,
        buttons: buttons

    });






})

//设置框架
$(function () {
    $("#page_style").frame({
        float: 'left',
        menu_nav: '.Quick_operation',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
$("#iframe_box").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/*********************/
require.config({
    paths: {
        echarts: './js/dist'
    }
});